<?php
// 应用公共文件
use think\facade\Db;
use \think\Log;

/**
 * //接口返回数据
 * @param $status
 * @param $message
 * @param $data
 * @param $httpStatus
 * @return \think\response\Json
 */
function show($status, $message = "error", $data = [], $httpStatus = 200)
{
    $result = [
        "status" => $status,
        "message" => $message,
        "result" => $data
    ];
    return json($result, $httpStatus);

}

/**
 * @param $string
 * @return string
 */
function getRandStr($string)
{
//        生成token
    $str = md5(uniqid(md5(microtime(true)), true));//生成一个不会重复的字符串
    //加密
    return sha1($str . $string);
}

function userLoginExpiresTime($day = 1)
{
    return intval($day) * 24 * 3600;
}

/**
 * sql语句打印
 */
function sql()
{
    Log::write((Db::getLastSql()).'123','notice');
    echo Db::getLastSql();
    exit;
}

function formatTimestamp($timestamp, $format = "Y-m-d") {
    return date($format, $timestamp);
}
